#include "AddCommand.h"

#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsItem>

AddCommand::AddCommand(bool itemType, int size, QPointF scenePos, QGraphicsScene *scene)
{
    this->scene = scene;
    this->scenePos = scenePos;

    if (itemType == false)
        item = new QGraphicsEllipseItem(0, 0, size, size); // Circulo
    else
        item = new QGraphicsRectItem(0, 0, size, size); // Cuadrado

    item->setFlag(QGraphicsItem::ItemIsSelectable, true);
    item->setFlag(QGraphicsItem::ItemIsMovable, true);

    QString type = (itemType == true)? "Rect" : "Ellipse";
    this->setText(QString("Add %1 At [%2, %3] Of %4 Px").arg(type).arg(scenePos.x()).arg(scenePos.y()).arg(size));
}

AddCommand::~AddCommand()
{
    delete item;
}

void AddCommand::redo()
{
    scene->addItem(item);
    item->setPos(scenePos);
}

void AddCommand::undo()
{
    scene->removeItem(item);
}
